<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

<form:form commandName="model" cssClass="validate"
	action="task/planTask/save">
	<form:hidden path="id" />
	<div class="header">
		<h2>
			&nbsp;&nbsp;任务信息<span><font color="red">（* 为必填项）</font> </span>
		</h2>
	</div>
	<table class=" form-table">
		<tbody>

			<tr>
				<td class="td1">编号：</td>
				<td class="td2"><form:input path="taskCode" maxlength="100"
						cssClass="required" />
				</td>
			</tr>
			<tr>
				<td class="td1">名称：</td>
				<td class="td2"><form:input path="taskName" maxlength="100"
						cssClass="required" style="width:380px" />
				</td>
			</tr>
			<tr>
				<td class="td1">任务类别：</td>
				<td class="td2"><isperp:dictSelector typeCode="TASK_TYPE"
						name="taskType" id="taskType" hasEmptyValue="true"
						dictCssClass="required" selectedValue="${model.taskType }"></isperp:dictSelector>
				</td>
			</tr>
			<tr>
				<td class="td1">所属项目：</td>
				<td class="td2"><form:select path="projectId" data-width="500"
						items="${projects}" itemLabel="name" itemValue="id"
						cssClass="search required" /></td>
			</tr>
			<tr>
				<td class="td1">所属项目阶段：</td>
				<td class="td2"><form:radiobuttons path="projectStage"
						items="${project_stage}" itemLabel="name" itemValue="name"
						cssClass="required" /><label class="required"></label>
				</td>
			</tr>
			<tr>
				<td class="td1">优先级：</td>
				<td class="td2"><form:radiobuttons path="taskPriority"
						items="${task_prioirty}" itemLabel="name" itemValue="name"
						cssClass="required" /><label class="required"></label>
				</td>
			</tr>
			<tr>
				<td class="td1">负责人：</td>
				<td class="td2"><form:hidden path="taskPrincipalId" /> <isperp:departmentUser
						displayValueCssClass="required"
						displayValue="${model.taskPrincipalName }"
						valueControlId="taskPrincipalId" id="taskPrincipalName"
						name="taskPrincipalName"></isperp:departmentUser></td>
			</tr>
			<tr>
				<td class="td1">内容：</td>
				<td class="td2"><form:textarea path="taskContent"
						maxlength="500" cssClass="required" cssStyle="width:60%" /></td>
			</tr>
			<tr>
				<td class="td1">目标：</td>
				<td class="td2"><form:textarea path="taskTarget"
						maxlength="500" cssStyle="width:60%" /></td>
			</tr>
			<tr>
				<td class="td1">交付标准：</td>
				<td class="td2"><form:textarea path="taskDeliverables"
						maxlength="500" cssStyle="width:60%" /></td>
			</tr>
			<tr>
				<td class="td1">计划工时(h)：</td>
				<td class="td2"><form:input path="planTimes" maxlength="10"
						cssClass="required number" cssStyle="width:60%" /></td>
			</tr>
			<tr>
				<td class="td1">巡检项：</td>
				<td class="td2"><form:hidden path="inspectTemplateDefId" /> <isperp:listSelector
						id="templateDefIdSelector" valueControlId="inspectTemplateDefId"
						inputReadonly="true" url="task/inspectTemplateDef/list"
						valueColumn="id" displayColumn="name"
						displayValue="${inspectTemplateDefName }">
						<isperp:column title="id" name="id" hidden="true"></isperp:column>
						<isperp:column title="名称" name="name"></isperp:column>
					</isperp:listSelector><a href="javascript:isperp.openDialog({contentUrl:'task/inspectTemplate/preview?defId=${model.inspectTemplateDefId }'})">预览模板</a>
			</tr>
		</tbody>
	</table>
	<div class="header">
		<h2>&nbsp;&nbsp;任务执行设置</h2>
	</div>
	<table class=" form-table">
		<tbody>
			<tr>
				<td class="td1">执行类型：</td>
				<td class="td2"><form:radiobuttons path="excuteType"
						class="radioButton_excuteType" items="${task_execute_Type}"
						onchange="excuteTypeOnchange(this)" itemLabel="name"
						itemValue="code" cssClass="required" /><label class="required"></label>
				</td>
			</tr>
			<tr id="trOne">
				<td class="td1">计划执行时间：</td>
				<td class="td2"><input id="excuteOnePlanStartTime"
					name="excuteOnePlanStartTime" type="datetime"
					value="<fmt:formatDate value="${model.excuteOnePlanStartTime}"
						pattern="yyyy-MM-dd HH:mm" />" />~<input
					id="excuteOnePlanEndTime" name="excuteOnePlanEndTime"
					type="datetime"
					value="<fmt:formatDate value="${model.excuteOnePlanEndTime}"
						pattern="yyyy-MM-dd HH:mm" />" />
				</td>
			</tr>
			<tr id="trMul_1">
				<td class="td1">执行周期：</td>
				<td class="td2"><input id="excutePeriodStart"
					name="excutePeriodStart" type="date"
					value="<fmt:formatDate value="${model.excutePeriodStart}"
						pattern="yyyy-MM-dd" />" />~<input
					id="excutePeriodEnd" name="excutePeriodEnd" type="date"
					value="<fmt:formatDate value="${model.excutePeriodEnd}"
						pattern="yyyy-MM-dd" />" />
				</td>
			</tr>
			<tr id="trMul_2">
				<td class="td1">执行频率：</td>
				<td class="td2"><table style="width: 100%" border="0">
						<tr>
							<td><form:radiobutton value="day" checked="checked"
									id="rdoDay" path="excuteFrequencyType" label="每天" />
							</td>
							<td></td>
						</tr>
						<tr>
							<td><form:radiobutton value="week" id="rdoWeek"
									path="excuteFrequencyType" label="每周" /></td>
							<td id="chkExcuteWeekDays" align="left"><form:checkboxes
									path="selectedWeekDays" items="${excute_WeekDays}"
									itemLabel="name" itemValue="code" /></td>
						</tr>
						<tr>
							<td colspan="2">
							<div>
							<form:radiobutton value="month" id="rdoMonth"
									path="excuteFrequencyType" label="每隔" />
									<input style="width:15px;" name="monthFrequency" id="monthFrequency" value="${model.monthFrequency }" class="number"/> <label>月</label>
									</div><div id="chkExcuteMonthDays" >
									<form:checkboxes
									path="selectedMonthDays" items="${excute_MonthDays}"
									itemLabel="name" itemValue="code" />
									</div>
							</td>
						</tr>
					</table></td>
			</tr>
			<tr id="trMul_3">
				<td class="td1">执行时间：</td>
				<td class="td2"><input id="excuteTimeStart"
					name="excuteTimeStart" type="time"
					value="<fmt:formatDate value="${model.excuteTimeStart}"
						pattern="HH:mm" />" />~<input
					id="excuteTimeEnd" name="excuteTimeEnd" type="time"
					value="<fmt:formatDate value="${model.excuteTimeEnd}"
						pattern="HH:mm" />" />
				</td>
			</tr>
		</tbody>
	</table>
	<div class="header">
		<h2>&nbsp;&nbsp;任务发布设置</h2>
	</div>
	<table class=" form-table">
		<tbody>
			<tr>
				<td class="td1">提前发布天数：</td>
				<td class="td2"><form:input path="releaseBeforeDays"
						maxlength="10" cssClass="number required" />(任务负责人可以提前收到该任务的通知)</td>
			</tr>
			<tr id="trOneTimePlanTime">
				<td class="td1">非工作日发布：</td>
				<td class="td2"><form:radiobutton value="1" label="是"
						path="releaseIfNotWorkday" /> <form:radiobutton 
						value="0" label="否" path="releaseIfNotWorkday" />(非工作日是否执行该任务)</td>
			</tr>
			<tr>
				<td class="td1">是否顺延：</td>
				<td class="td2"><form:radiobutton value="1" label="是"
						checked="checked" path="releaseIfDelay" /> <form:radiobutton
						value="0" label="否" path="releaseIfDelay" />(如果非工作日不执行该任务，是否顺延迟到接下来第一个工作日执行)</td>
			</tr>
		</tbody>
	</table>


</form:form>
<isperp:buttonList>
	<button class="submit" onclick="isperp.submitForm();return false;">
		<span class="icon icon-save"></span>提交
	</button>
</isperp:buttonList>
<script type="text/javascript">
	//选择任务执行类型时，显示、隐藏相关控件
	//选择一次性任务时，显示计划完成时间，隐藏执行周期、执行频率、执行时间等；选择周期性任务时，反之
	function excuteTypeOnchange(obj) {

		if ($(obj).val() == "ONETIME") {
			$("#trOne").show();
			$("#trMul_1").hide();
			$("#trMul_2").hide();
			$("#trMul_3").hide();

		} else {
			$("#trOne").hide();
			$("#trMul_1").show();
			$("#trMul_2").show();
			$("#trMul_3").show();
		}

	}
	$(document).ready(function() {

		$("#rdoDay").change(function() {
			onExcuteFrequencyType($(this).val());
		});
		$("#rdoWeek").change(function() {
			onExcuteFrequencyType($(this).val());
		});
		$("#rdoMonth").change(function() {
			onExcuteFrequencyType($(this).val());
		});
		function onExcuteFrequencyType(excuteFrequencyType) {
			if (excuteFrequencyType == "day") {
				$("#chkExcuteWeekDays").hide();
				$("#chkExcuteMonthDays").hide();
			} else if (excuteFrequencyType == "week") {
				$("#chkExcuteWeekDays").show();
				$("#chkExcuteMonthDays").hide();
			} else {
				$("#chkExcuteWeekDays").hide();
				$("#chkExcuteMonthDays").show();
			}
		}

		var selectedExcuteType = $("input[name='excuteType']:checked").val();

		if (selectedExcuteType == "ONETIME") {
			$("#trOne").show();
			$("#trMul_1").hide();
			$("#trMul_2").hide();
			$("#trMul_3").hide();

		} else {
			$("#trOne").hide();
			$("#trMul_1").show();
			$("#trMul_2").show();
			$("#trMul_3").show();

			var selectedExcuteFrequencyType = $("input[name='excuteFrequencyType']:checked").val();
			onExcuteFrequencyType(selectedExcuteFrequencyType);

		}
		
		if('${model.taskCode}'=='')
		{
		  $.ajax({
		    url:'configuration/ci/getSeqByTableName?tableName=tsk_plan_task',
		    success:function(data)
		    {
		      if(data)
		      {
		        $("#taskCode").val(data);
		      }
		    }
		  });
		}

	});
</script>